package com.zzj.service.impl;

import com.zzj.bean.TabInventory;
import com.zzj.bean.TabSupplier;
import com.zzj.dao.TabInventoryMapper;
import com.zzj.service.TabInventoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * InnoDB free: 8192 kB 服务实现类
 * </p>
 *
 * @author 花
 * @since 2022-03-04
 */
@Service
public class TabInventoryServiceImpl extends ServiceImpl<TabInventoryMapper, TabInventory> implements TabInventoryService {

    @Resource
    private TabInventoryMapper tabInventoryMapper;

    @Override
    public boolean updateCount(TabInventory tabInventory) {
//        查找是库中是否有该种花
        TabInventory byFname = tabInventoryMapper.findByFname(tabInventory.getFname());
        System.out.println(byFname);
        if (byFname==null){
//            如果没有  则新增一条
            tabInventoryMapper.insert(tabInventory);
        }else{
//            如果有 则在原来花的基础上新增数量
            tabInventoryMapper.updateCount(tabInventory.getIcount(),tabInventory.getFname());
        }

        return true;
    }

    /**根据花名修改状态
     * @param tabInventory
     * @return
     */
    @Override
    public boolean updateStatus(TabInventory tabInventory) {
        if(tabInventory.getIstatus().equals("1")){
            tabInventoryMapper.updateStatus("0",tabInventory.getFname());
        }else if(tabInventory.getIstatus().equals("0")){
            tabInventoryMapper.updateStatus("1",tabInventory.getFname());
        }
        return true;
    }
}
